package org.shopen.puremvc.model.domain.testing
{
	import mx.collections.ArrayCollection;
	
	public class ChoiceTest extends Test
	{
		public static const TYPE : String = "choice";
		
		public function ChoiceTest(node:XML=null)
		{
			super(node);
		}
		
		override public function getType():String
		{
			return ChoiceTest.TYPE;
		}
		
		override public function getPoints(userAnswer:ArrayCollection):Number
		{
			var result : Number = 0;
			var rawPoints : Number = 0;
			var counter : Number = 0;
			var positiveCounter : Number = 0;
			var isCorrect : Boolean;
			for each (var option : Option in options.optionsArray)
			{
				isCorrect = option.checkCorrect(userAnswer.getItemAt(counter));
				if (option.correctValue == "true")
				{
					++positiveCounter;
					rawPoints += isCorrect ? 1 : 0;
				}
				counter++;
			}
			if (positiveCounter == 0)
			{
				result = points;
			}
			else
			{
				result = rawPoints / positiveCounter * points;
			}
			return result;
		}
		
		override public function clone():Test
		{
			var result : ChoiceTest = new ChoiceTest();
			cloneFileds(result);
			return result;
		}
	}
}